<?php
/*
	监听会员购买满额事件
*/
defined('BY_JYA') or exit('error');

//查询会员购买总金额
$sql = "SELECT SUM(price) FROM " . tablename('jy_weishop_order') . " WHERE uniacid=:uniacid AND ispay=1 AND mid=:mid ";
$all = pdo_fetch($sql,array(":uniacid" => $_SESSION['uniacid'],":mid" => $_SESSION['uid']));	
//查询会员的充值满额的任务
$tasks=pdo_getall('jy_renwu_task_record',array('uniacid'=>$_SESSION['uniacid'],'mid'=>$mid,'tasktype'=>'order_all','stoptime >'=>time(),'finishtime >'=>'0'));
if($tasks){
	//修改任务状态为完成
	foreach($tasks as $task){
		if($task['task_demand'] <= $all['SUM(price)']){
		pdo_update('jy_renwu_task_record',array('finishtime'=>$time),array('id'=>$task['id']));
		}
	}
}